/************************************************************************/
/*    Author: Scott Bevin                                               */
/************************************************************************/

#pragma once

#include <ogre.h>
#include <string>
#include <vector>
#include <map>

#include "GameEntity.h"
#include "../XInput/Input.h"
#include "../XUtilities/Utilities.h"

#define ENTITY_FILE_EXTENSION ".txt" //so we can change it to .AWESOMEFILE or something =]

namespace XF
{
	class GameEntityManager
	{
	private:
		XF::DebugDisplay* mGameEnityLog;
		GameEntity* mNewGameEntity;

		std::map<std::string, std::string> mFilepathMap;
		std::map<std::string, GameEntity*> mEntityCache;

		std::vector<GameEntity*> mDeadEntitys;
		

		void FileParserCallback(std::string key, std::vector<std::string> &arguments);
		void ConfigFileParserCallback(std::string key, std::vector<std::string> &arguments);

		GameEntityManager();
		static GameEntityManager* smInstance;

	public:
		std::vector<GameEntity*> mAliveEntitys;
		bool mPauseEntities;
		~GameEntityManager();

		static bool Initialize(std::string configFilePath);

		static GameEntityManager* GetInstance()
		{
			Utilities::Assert(smInstance != NULL, "GameEntityManager::GetInstance: Initialize not called");

			return smInstance;
		}

		void Pause(){mPauseEntities = true;}
		void UnPause(){mPauseEntities = false;}
		GameEntity* CreateGameEntity(std::string fileName);
		GameEntity* LookUpGameEntity(std::string fileName);
		bool PreloadAllEntityScripts();

		void ClearCache();	

		void CleanupDeads();
		void KillAllEntitys();

		void HandleInput(double dt, Input *input);
		void Update(double dT);
	};
}